package com.mjf.quartz.task;

import cn.hutool.core.util.StrUtil;
import com.mjf.cjt.service.AsyncTMService;
import com.mjf.common.utils.DateUtils;
import com.mjf.jst.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * desc
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/5/22 16:59
 */
@Component("jstTask")
@Slf4j
public class JstTask {

    @Autowired
    private JSTAsyncService asyncTMService;
    @Autowired
    private ShopInfoService shopInfoService;
    @Autowired
    private BcJstSalesOutTService bcJstSalesOutTService;
    @Autowired
    private BcCjstSkuService bcCjstSkuService;
    @Autowired
    private IWMSWarehouseService wmsWarehouseService;
    /**
     * 拉取店铺列表
     */
    public void pullShopsList() {
        log.info("开始执行定时任务：拉取仓库列表");
        shopInfoService.pullShopsList();
        log.info("结束执行定时任务：拉取仓库列表");
    }
    /**
     * 拉取仓库列表
     */
    public void pullWmsList() {
        log.info("开始执行定时任务：拉取仓库列表");
        wmsWarehouseService.pullWmsList();
        log.info("结束执行定时任务：拉取仓库列表");
    }

    /**
     * 拉取销售出库列表
     */
    public void pullSalesoutList(String start, String end)
    {
        if (StrUtil.isBlank(start)) {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            start = dateTimeFormatter.format(LocalDate.now().minusDays(1)) + " 00:00:00";
            end = dateTimeFormatter.format(LocalDate.now().minusDays(1)) + " 23:59:59";
        }
        log.info("开始执行定时任务：拉取销售出库列表");
        bcJstSalesOutTService.asyncSalesout(start, end);
        log.info("结束执行定时任务：拉取销售出库列表");
    }

    /**
     * 同步商品
     */
    public void asyncProduct(String start, String end) {
        if (StrUtil.isBlank(start)) {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            start = dateTimeFormatter.format(LocalDate.now().minusDays(1)) + " 00:00:00";
            end = dateTimeFormatter.format(LocalDate.now().minusDays(1)) + " 23:59:59";
        }
        bcCjstSkuService.asyncProduct(start, end);
    }

}
